Add GTK_ICON_LOOKUP_GENERIC_FALLBACK icon lookup flag and implement it.
authorMatthias Clasen <mclasen@redhat.com>
Thu, 19 Apr 2007 04:14:39 +0000 (04:14 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Thu, 19 Apr 2007 04:14:39 +0000 (04:14 +0000)
2007-04-19  Matthias Clasen  <mclasen@redhat.com>

        * gtk/gtkicontheme.h:
        * gtk/gtkicontheme.c: Add GTK_ICON_LOOKUP_GENERIC_FALLBACK
        icon lookup flag and implement it.  (#396901, Luca Ferreti)

svn path=/trunk/; revision=17611

ChangeLog
gtk/gtkicontheme.c
gtk/gtkicontheme.h

index 1bcb9fecad5ccdb69e183c971b5d943a229d2e4a..c35da9a24eb0eb1e0bbd754d98787f0943967f30 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-04-19  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtkicontheme.h:
+       * gtk/gtkicontheme.c: Add GTK_ICON_LOOKUP_GENERIC_FALLBACK
+       icon lookup flag and implement it.  (#396901, Luca Ferreti)
+       
 2007-04-18  Richard Hult  <richard@imendio.com>
 
        * gdk/quartz/gdkwindow-quartz.c:
index 3f07e61829775331882f819946f6568e8d132926..6eb4aa01abfcaddafe6d259af63449c1b336b4cb 100644 (file)
@@ -1256,6 +1256,7 @@ gtk_icon_theme_lookup_icon (GtkIconTheme       *icon_theme,
   UnthemedIcon *unthemed_icon;
   gboolean allow_svg;
   gboolean use_builtin;
+  gboolean generic_fallback;
 
   g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
   g_return_val_if_fail (icon_name != NULL, NULL);
@@ -1273,15 +1274,33 @@ gtk_icon_theme_lookup_icon (GtkIconTheme       *icon_theme,
   else
     allow_svg = priv->pixbuf_supports_svg;
 
-  use_builtin = (flags & GTK_ICON_LOOKUP_USE_BUILTIN);
-
+  use_builtin = flags & GTK_ICON_LOOKUP_USE_BUILTIN;
+  generic_fallback = flags & GTK_ICON_LOOKUP_GENERIC_FALLBACK;
+  
   ensure_valid_themes (icon_theme);
 
   for (l = priv->themes; l; l = l->next)
     {
       IconTheme *theme = l->data;
       
-      icon_info = theme_lookup_icon (theme, icon_name, size, allow_svg, use_builtin);
+      gchar *name = g_strdup (icon_name);
+      gchar *s;
+
+      while (TRUE)
+        {
+          icon_info = theme_lookup_icon (theme, name, size, allow_svg, use_builtin);
+          if (icon_info || !generic_fallback)
+            break;
+
+          s = strrchr (name, '-');
+          if (!s)
+            break;
+  
+          *s = '\0';   
+        }
+
+      g_free (name); 
+
       if (icon_info)
        goto out;
     }
index 8a0ae125ab4464d6fa3411b99d0c55293c33edac..cef75e7121c56f63615aa298239f6a71ff04966c 100644 (file)
@@ -66,6 +66,8 @@ struct _GtkIconThemeClass
  *   gtk_icon_theme_lookup_icon() includes builtin icons
  *   as well as files. For a builtin icon, gtk_icon_info_get_filename()
  *   returns %NULL and you need to call gtk_icon_info_get_builtin_pixbuf().
+ * @GTK_ICON_LOOKUP_GENERIC_FALLBACK: Try to shorten icon name at '-'
+ *   characters before looking at inherited themes. 
  * 
  * Used to specify options for gtk_icon_theme_lookup_icon()
  **/
@@ -73,7 +75,8 @@ typedef enum
 {
   GTK_ICON_LOOKUP_NO_SVG = 1 << 0,
   GTK_ICON_LOOKUP_FORCE_SVG = 1 << 1,
-  GTK_ICON_LOOKUP_USE_BUILTIN = 1 << 2
+  GTK_ICON_LOOKUP_USE_BUILTIN = 1 << 2,
+  GTK_ICON_LOOKUP_GENERIC_FALLBACK = 1 << 3
 } GtkIconLookupFlags;
 
 #define GTK_ICON_THEME_ERROR gtk_icon_theme_error_quark ()